﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Zhang.DeskTop
{
    /// <summary>
    /// 基类
    /// </summary>
    public partial class BaseController: System.Web.Mvc.Controller
    {
        /// <summary>
        /// 会员信息
        /// </summary>
        public Model.UCenter.MUser MUser { get; set; }

        #region 直接返回序列化结果
        protected virtual JsonResult RSuccess<T>(T data)
        {
            return Json(new { Data = data, Code = 200, Message = "操作成功" }, JsonRequestBehavior.AllowGet);
        }

        protected virtual JsonResult RSuccess<T>(T data, string message)
        {
            return Json(new { Data = data, Code = 200, Message = message }, JsonRequestBehavior.AllowGet);
        }

        protected virtual JsonResult RSuccess<T>(T data, string message, string redirect)
        {
            return Json(new { Data = data, Code = 200, Message = message, Redirect = redirect }, JsonRequestBehavior.AllowGet);
        }

        protected virtual JsonResult RSuccessMessage(string message)
        {
            return Json(new { Code = 200, Message = message }, JsonRequestBehavior.AllowGet);

        }

        protected virtual JsonResult RSuccessMessage(string message, string redirect)
        {
            return Json(new { Code = 200, Message = message, Redirect = redirect }, JsonRequestBehavior.AllowGet);
        }


        protected virtual JsonResult RError<T>(T data)
        {
            return Json(new { Data = data, Code = 400, Message = "操作失败" }, JsonRequestBehavior.AllowGet);
        }

        protected virtual JsonResult RError<T>(T data, string message)
        {
            return Json(new { Data = data, Code = 400, Message = message }, JsonRequestBehavior.AllowGet);
        }

        protected virtual JsonResult RErrorMessage(string message)
        {
            return Json(new { Code = 400, Message = message }, JsonRequestBehavior.AllowGet);
        }

        #endregion
    }
}
